package it.xiuxian.login.presenter

import android.widget.Toast
import com.lzy.okgo.OkGo
import it.xiuxian.lib.base.BaseBean
import it.xiuxian.lib.base.BasePresenter
import it.xiuxian.lib.base.ILoadBind
import it.xiuxian.lib.http.CallBackOption
import it.xiuxian.lib.http.HttpConfig
import it.xiuxian.lib.utils.EncodeUtils
import it.xiuxian.lib.utils.ToastUtil
import it.xiuxian.login.activity.ForgetPwdActivity
import it.xiuxian.login.bean.CodeBean
import it.xiuxian.login.bean.LoginBean
import org.json.JSONObject

class ForgetPwdActivityPresenter:BasePresenter<ForgetPwdActivity>() {
    fun getCode(phone: String,type:String) {
        var json1 = JSONObject()
        json1.put("loginname",phone)
        OkGo.post<BaseBean<String>>(HttpConfig.BASE_URL + "/appuserpassword/sendForGetSendSMS")
            .params("encrypt", EncodeUtils.encodeAES(json1.toString()))
            .execute(object : CallBackOption<BaseBean<String>>() {}
                .loadBind(mView as ForgetPwdActivity)
                .execute(object : ILoadBind<BaseBean<String>> {
                    override fun excute(bean: BaseBean<String>) {
                        (mView as ForgetPwdActivity).update(bean)
                    }
                })
            )
    }

    fun forgetPwd(phone: String,password:String,password_confirm:String,code:String){
        var json1 = JSONObject()
        json1.put("loginname",phone)
            .put("password",password)
            .put("code",code)
        OkGo.post<BaseBean<String>>(HttpConfig.BASE_URL + "/appuserpassword/forGetPassWord")
            .params("encrypt", EncodeUtils.encodeAES(json1.toString()))
            .execute(object : CallBackOption<BaseBean<String>>() {}
                .loadBind(mView as ForgetPwdActivity)
                .execute(object : ILoadBind<BaseBean<String>> {
                    override fun excute(bean: BaseBean<String>) {
                        ToastUtil.showShort(bean.msg)
                        (mView as ForgetPwdActivity).setUI(bean.code)
                    }
                })
            )
    }
}